# -*- coding:utf-8 -*-
from functools import total_ordering


class Employee:
    """所有员工的基类"""
    empCount = 0

    def __init__(self, name, salary: float):
        self.name = name
        self.salary = salary
        Employee.empCount += 1

    @classmethod
    def display_count(cls):
        print("Total Employee %d" % cls.empCount)

    def display_employee(self):
        print("Name : ", self.name, ", Salary: ", self.salary)


@total_ordering  # 补充比较方法
class Programmer(Employee):
    """程序员"""

    def __init__(self, job, name, salary):
        self.job = job
        Employee.__init__(self, name, salary)

    def display_all(self):
        print("Name : ", self.name, "job : ", self.job, ", Salary: ", self.salary)

    def __eq__(self, other):
        if isinstance(other, Programmer):
            if self.salary == other.salary:
                return True
            else:
                return False
        else:
            raise Exception('对象类必须是Programmer')

    def __lt__(self, other):
        if isinstance(other, Programmer):
            if self.salary < other.salary:
                return True
            else:
                return False
        else:
            raise Exception('对象类必须是Programmer')

    def __add__(self, other):  # 加
        if isinstance(other, Programmer):
            return other.salary + self.salary
        else:
            raise Exception('对象类必须是Programmer')

    def __sub__(self, other):  # 减
        if isinstance(other, Programmer):
            return self.salary - other.salary
        else:
            raise Exception('对象类必须是Programmer')

    def __str__(self):
        return '{}工资是{}'.format(self.name,self.salary)

    def __getattr__(self, item):
        return '不存在这个属性'

    def __getattribute__(self, item):
        return Employee.__getattribute__(self,item)

    # def __dir__(self):
    #     return self.__dict__.keys()


if __name__ == '__main__':
    dp1 = Programmer(job='sss', name='yyy', salary=10)
    print(dp1.empCount)
    dp2 = Programmer(job='sss', name='yfff', salary=10001)
    print(dp1)
    print(dp1.empCount)
    print(dp1 >= dp2)
    print(dp1 + dp2)
    print(dp1 - dp2)
    # print(dir(dp1))
    print(dp1.s)
    # print(dir(dp))
    # print(isinstance(dp, Programmer))
    # print(dp.__dict__)
